import request from '@/util/request'
// 获取文章相关数据的 api

export function getArticles(params) {
  return request({
    method: 'get',
    url: '/api/articles',
    params
  })
}

export function getFeedArticles(params) {
  return request({
    method: 'get',
    url: '/api/articles/feed',
    params
  })
}

export function getArticle(slug) {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}`
  })
}

export function favoriteArticle(slug) {
  return request({
    method: 'POST',
    url: `/api/articles/${slug}/favorite`
  })
}

export function unfavoriteArticle(slug) {
  return request({
    method: 'DELETE',
    url: `/api/articles/${slug}/favorite`
  })
}

export function createArticle(data) {
  return request({
    method: 'POST',
    url: '/api/articles',
    data
  })
}

export function updateArticle(slug, data) {
  return request({
    method: 'PUT',
    url: `/api/articles/${slug}`,
    data
  })
}

export function deleteArticle(slug) {
  return request({
    method: 'DELETE',
    url: `/api/articles/${slug}`
  })
}

export function getComments(slug) {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}/comments`
  })
}

export function publishComment(slug, data) {
  return request({
    method: 'POST',
    url: `/api/articles/${slug}/comments`,
    data
  })
}

export function deleteComment(slug, id) {
  return request({
    method: 'DELETE',
    url: `/api/articles/${slug}/comments/${id}`
  })
}